﻿$(function () {
    var screenwidth, screenheight, mytop, getPosLeft1, getPosTop1, getPosLeft2, getPosTop2, getPosLeft3, getPosTop3
    screenwidth = $(window).width();
    screenheight = $(window).height();
    //获取滚动条距顶部的偏移
    mytop = $(document).scrollTop();
    //css定位弹出层
    var getPosLeft1 = (screenwidth - $("div.popupWindow").width()) / 2;
    var getPosTop1 = (screenheight - $("div.popupWindow").height()) / 2;
    var getPosLeft2 = (screenwidth - $("div.popupWindowSuggestion").width()) / 2;
    var getPosTop2 = (screenheight - $("div.popupWindowSuggestion").height()) / 2;
    var getPosLeft3 = (screenwidth - $("div.popupWindowNeedDirector").width()) / 2;
    var getPosTop3 = (screenheight - $("div.popupWindowNeedDirector").height()) / 2;
    $("div.popupWindow").css({ "left": getPosLeft1, "top": getPosTop1 });
    $("div.popupWindowSuggestion").css({ "left": getPosLeft2, "top": getPosTop2 });
    $("div.popupWindowNeedDirector").css({ "left": getPosLeft3, "top": getPosTop3 });
    //当浏览器窗口大小改变时
    $(window).resize(function () {
        screenwidth = $(window).width();
        screenheight = $(window).height();
        mytop = $(document).scrollTop();
        getPosLeft = screenwidth / 2 - 340;
        getPosTop = screenheight / 2 - 150;
        $("div.popupWindow").css({ "left": getPosLeft1, "top": getPosTop1 + mytop });
        $("div.popupWindowSuggestion").css({ "left": getPosLeft2, "top": getPosTop2 + mytop });
        $("div.popupWindowNeedDirector").css({ "left": getPosLeft3, "top": getPosTop3 + mytop });
    });
    //当拉动滚动条时，弹出层跟着移动
    $(window).scroll(function () {
        screenwidth = $(window).width();
        screenheight = $(window).height();
        mytop = $(document).scrollTop();
        getPosLeft = screenwidth / 2 - 340;
        getPosTop = screenheight / 2 - 150;
        $("div.popupWindow").css({ "left": getPosLeft1, "top": getPosTop1 + mytop });
        $("div.popupWindowSuggestion").css({ "left": getPosLeft2, "top": getPosTop2 + mytop });
        $("div.popupWindowNeedDirector").css({ "left": getPosLeft3, "top": getPosTop3 + mytop });
    });
    //点击关闭弹出窗口
    $("input[type='button']#btnCloseSuggestion").click(function () {
        $("div.popupWindow").hide();
        $("#greybackground").hide();
        return false;
    });
});